﻿using System;
using System.ComponentModel;
using System.Windows.Input;

namespace ebcpatterns.wpf
{
    public class FlowCommand<TMessage> : ICommand, INotifyPropertyChanged
    {
        private bool isEnabled = true;

        public void Execute(object parameter) {
            Process((TMessage)parameter);
        }

        public bool CanExecute(object parameter) {
            return isEnabled;
        }

        public event EventHandler CanExecuteChanged = delegate {};

        public bool IsEnabled {
            get { return isEnabled; }
            set {
                isEnabled = value;
                CanExecuteChanged(this, EventArgs.Empty);
                PropertyChanged(this, new PropertyChangedEventArgs("IsEnabled"));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        public event Action<TMessage> Process;
    }

    public class FlowCommand : ICommand, INotifyPropertyChanged
    {
        private bool isEnabled = true;

        public void Execute(object parameter) {
            Process();
        }

        public bool CanExecute(object parameter) {
            return isEnabled;
        }

        public bool IsEnabled {
            get { return isEnabled; }
            set {
                isEnabled = value;
                CanExecuteChanged(this, EventArgs.Empty);
                PropertyChanged(this, new PropertyChangedEventArgs("IsEnabled"));
            }
        }

        public event EventHandler CanExecuteChanged = delegate { };

        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        public event Action Process;
    }
}